package com.example.demo.repository;


import com.example.demo.entity.Comment;
import com.example.demo.entity.Like;
import com.example.demo.entity.Post;
import com.example.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface LikeRepository extends JpaRepository<Like, Long> {

    //统计某个文章的点赞数
    Long countByPost(Post post);

    //统计某条评论的点赞数
    Long countByComment(Comment comment);

    //检查用户是否为某篇文章点赞
    boolean existsByPostAndUser(Post post, User user);
    Optional<Like> findByPostAndUser(Post post, User user);

    //检查用户是否为某个评论点赞
    boolean existsByCommentAndUser(Comment comment, User user);
    Optional<Like> findByCommentAndUser(Comment comment, User user);
}
